package crp.core.portal.app.storage;

import crp.core.shared.Configs;
import crp.core.shared.StorageBuckets;
import com.qwlabs.cdi.Dispatchable;
import com.qwlabs.storage.models.StoragePlan;
import com.qwlabs.storage.services.StorageContext;
import com.qwlabs.storage.services.StoragePlanner;

import javax.enterprise.context.ApplicationScoped;
import java.util.Objects;

@ApplicationScoped
public class BannerStoragePlanner implements StoragePlanner, Dispatchable<StorageContext> {
    private static final String BUSINESS_TYPE = "banner";
    private static final String OBJECT_NAME_FORMAT = "%s/%s";

    @Override
    public StoragePlan plan(StorageContext context) {
        String objectName = String.format(OBJECT_NAME_FORMAT, context.getFileHash(), context.getFileName());
        return new StoragePlan(Configs.DEFAULT_ENV, StorageBuckets.BANNER, objectName);
    }

    @Override
    public boolean dispatchable(StorageContext context) {
        return Objects.equals(context.getBusinessType(), BUSINESS_TYPE);
    }
}
